package com.easy.work.function.mall;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.base.syslib.util.MessageTools;
import com.easy.work.R;
import com.easy.work.app.BaseActivity;
import com.easy.work.bean.MallGoodsBean;
import com.easy.work.function.mall.activity.CommitOrderActivity;
import com.squareup.picasso.Picasso;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Admin on 2018/1/3.
 * 商品详情
 */
public class CommodityDetailAct extends BaseActivity {
    @BindView(R.id.img_commodity_detail)
    ImageView imgCommodityDetail;
    @BindView(R.id.tv_commodity_name)
    TextView tvCommodityName;
    @BindView(R.id.tv_integral)
    TextView tvIntegral;
    @BindView(R.id.tv_price_rmb)
    TextView tvPriceRmb;
    @BindView(R.id.tv_integral_buy)
    TextView tvIntegralBuy;
    @BindView(R.id.rl_exchange)
    RelativeLayout rlExchange;
    @BindView(R.id.rl_back)
    RelativeLayout rlBack;
    private MallGoodsBean bean;
    /**
     * title变色高度
     */
    private int length;

    public static void start(Context ctx, MallGoodsBean bean) {
        Intent intent = new Intent(ctx, CommodityDetailAct.class);
        intent.putExtra("MallGoodsBean", bean);
        ctx.startActivity(intent);
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        isSetBatteryBar = false;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_commodity_detail);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        bean = (MallGoodsBean) getIntent().getSerializableExtra("MallGoodsBean");
        if (bean == null) {
            return;
        }
        Picasso.with(oThis).load(bean.goodsImageB).into(imgCommodityDetail);
        tvCommodityName.setText(bean.goodsName);
        tvIntegral.setText(bean.integral + "");
        tvIntegralBuy.setText(bean.integral + "");
        tvPriceRmb.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        rlBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @OnClick(R.id.rl_exchange)
    public void onViewClicked() {
        if (bean == null) {
            MessageTools.showToast(oThis, "获取商品信息失败");
            return;
        }
        if (bean.inventory < 1) {
            MessageTools.showToast(oThis, "暂无库存");
            return;
        }
        MessageTools.showDialog(oThis, "是否兑换商品" + bean.goodsName, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                CommitOrderActivity.start(oThis, bean);
            }
        });
    }

}
